package org.cnbi.service.impl;


import org.cnbi.dao.IHandleDao;
import org.cnbi.entity.SysLog;
import org.cnbi.entity.User;
import org.cnbi.service.ISystemService;
import org.cnbi.service.IUserService;
import org.cnbi.utils.exception.BusinessException;
import org.cnbi.utils.pagination.PagingUtil;
import org.cnbi.utils.pojo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * Copyright © 2014中国经邦. All rights reserved.
 * ----User Manage 用户管理Service
 * @author zhh
 * @date 2014年4月24日下午16:04
 * @cnbi-service
 */
@Service("userService")
public class IUserServiceImpl implements  IUserService{
	
	@Autowired
	private IHandleDao handleDao;
	
	/**
	 * 查询用户
	 * @param String sql sql语句
	 * @param User user numPerPage每页显示数
	 * @param map 参数 传递
	 * @return Pagination 分页    & 数据集合
	 * **/
	@Override
	public Pagination queryList(PagingUtil page, User user) {
		try {
			return handleDao.queryPagination(page, user);
		} catch (Exception e) {
			throw new BusinessException("执行..查询[用户列表]..."+page.getSql()+e.getMessage());
		}
	}
	
	/**
	 * @  添加用户
	 * @param sql
	 * @param user 用户
	 * **/
	@Override
	public void addUser(String sql,User user) {
		try {
			handleDao.execute(sql, user);
		} catch (Exception e) {
			throw new BusinessException("执行..[添加用户]..."+sql+e.getMessage());
		}
		
	}
	
	/**
	 * 修改用户
	 * @param sql
	 * @param user 用户
	 * **/
	@Override
	public void updateUser(String sql, User user) {
		try {
			handleDao.execute(sql, user);
		} catch (Exception e) {
			throw new BusinessException("执行..[修改用户]..."+sql+e.getMessage());
		}
	}
	
	/**
	 * 删除用户
	 * @param sql
	 * @param user 用户
	 * **/
	@Override
	public void deleteUser(String sql, User user) {
		try {
			handleDao.execute(sql, user);
		} catch (Exception e) {
			throw new BusinessException("执行..[删除用户]..."+sql+e.getMessage());
		}
		
	}
	
	/**
	 * 查询用户名是否寻在
	 * @param sql 
	 * @param user 用户
	 * @return int 
	 * **/
	@Override
	//@Cacheable(value = "locationSearchCache", key = "")
	public int queryIsNot(String sql, User user) {
		try {
			return handleDao.queryCount(sql,user);
		} catch (Exception e) {
			throw new BusinessException("执行..[查询当前用户名 出错]..."+sql+e.getMessage());
		}
		
	}

}
